//
//  UITextView+CPCapture.m
//  ChinaPoem
//
//  Created by 赵俊明 on 2019/3/7.
//  Copyright © 2019 赵俊明. All rights reserved.
//

#import "UITextView+CPCapture.h"

@implementation UITextView (CPCapture)
- (UIImage *)screenShotImage
{
    UIImage* image =nil;
    UIGraphicsBeginImageContextWithOptions(self.contentSize,NO,0.0);
    {
        CGPoint savedContentOffset = self.contentOffset;
        CGRect savedFrame = self.frame;
        self.contentOffset= CGPointZero;
        self.frame= CGRectMake(0, 0, self.contentSize.width,self.contentSize.height);
        
        [self.layer renderInContext: UIGraphicsGetCurrentContext()];
        image= UIGraphicsGetImageFromCurrentImageContext();
        
        self.contentOffset= savedContentOffset;
        self.frame= savedFrame;
    }
    UIGraphicsEndImageContext();
    
    if(image != nil) {
        return image;
    }
    return nil;
}
@end
